package org.xtext.runtime.lang;

import java.util.LinkedList;
import java.util.List;

import org.xtext.runtime.formula.Predicate;
import org.xtext.runtime.interpreter.ActionParam;
import org.xtext.runtime.library.Library;
import org.xtext.runtime.term.ITerm;
import org.xtext.runtime.term.Term;

public class Math extends Library {
	@TERM
	public int addition(int x, int y) {
		return x+y;
	}

	@ACTION
	public boolean addition(int x, int y, ActionParam<Integer> result) {
		result.set(x+y);
		return true;
	}
	
	@FORMULA
	public boolean lessThan(int x, int y) {
		return x < y;
	}
	
	@SENSOR
	public List<Predicate> random() {
		List<Predicate> list = new LinkedList<Predicate>();
		list.add(new Predicate("random", new ITerm[] {Term.newInstance(java.lang.Math.random())}));
		return list;
	}
	
	@TERM
	public int intValue(String value) {
		return Integer.parseInt(value);
	}
}
